package com.sgb.kjwl.view.ui.adapter.material;

import android.content.Context;
import android.text.TextUtils;
import android.widget.TextView;

import com.sgb.kjwl.BR;
import com.sgb.kjwl.R;
import com.sgb.kjwl.model.entity.AdmixtureEntity;
import com.swgk.core.recyclerview.adapter.BaseRecycleAdapter;
import com.swgk.core.recyclerview.adapter.ItemViewHolder;

import java.util.HashMap;
import java.util.List;

/**
 * 商砼添加剂
 */
public class ConcreteAdmixAdapter extends BaseRecycleAdapter<AdmixtureEntity> {

    private final HashMap<Integer, Integer> map;

    public ConcreteAdmixAdapter(Context context, List<AdmixtureEntity> data) {
        super(context, R.layout.item_concrete_admix, data);
        map = new HashMap<>();
        for (int i = 0; i < data.size(); i++) {
            int select = 0;
            for (int j = 0; j < data.get(i).getSpec().size(); j++) {
                if (!TextUtils.isEmpty(data.get(i).getSpec().get(j).getIsChoose()) && data.get(i).getSpec().get(j).getIsChoose().equals("1")) {
                    select = j;
                }
            }
            map.put(i, select);
        }
    }

    @Override
    public void convert(ItemViewHolder holder, AdmixtureEntity entity) {
        holder.setBinding(BR.viewModel, entity);
        TextView value = holder.itemView.findViewById(R.id.value);

        if (map.get(holder.getPosition()) == 0) {
            value.setText(entity.getAdmixtureName());
            value.setTextColor(context.getResources().getColor(R.color.color_666666));
            value.setBackground(context.getResources().getDrawable(R.drawable.corner2_f5f5f5_bg));
        } else {
            String name = entity.getSpec().get(map.get(holder.getPosition())).getName();
            value.setText(TextUtils.isEmpty(name) ? entity.getAdmixtureName() : name);
            value.setTextColor(context.getResources().getColor(R.color.color_main));
            value.setBackground(context.getResources().getDrawable(R.drawable.corner2_105792fd_bg));
        }
    }

    public void setSelect(int index1, int index2) {
        map.put(index1, index2);
    }

    public HashMap<Integer, Integer> getSelect() {
        return map;
    }
}
